<?php
class Admin_Model_Subjects
{
	public static function getList()
	{
		$sub_obj = new Application_Model_Db_Subjects();
		$sis_obj = new Application_Model_Db_SubInSem();
		$temp = $sub_obj->fetchAll();
		$select = $sis_obj->select();
		$out = array();
		foreach($temp as $row){
			$row = $row->toArray();
			$select->from(	$sis_obj,	array('COUNT(subject_in_semester.group_id ) as count',))
						->where('subject_in_semester.subject_id = ?', $row['subject_id'])
						//->group('subject_in_semester.group_id')
						->distinct(true);
			$count = $sis_obj->fetchRow($select);
			//var_dump($count);
			$out[] = array_merge($row,$count->toArray(),array('json'=>json_encode($row)));
		}
		return $out;
	}
	public static function addGroup($data, $id=null)
	{
		$obj = new Application_Model_Db_SubInSem();
		$rt = $obj->insert($data);
		var_dump($rt);
	} 
	public static function addSubject($data)
	{
		$obj = new Application_Model_Db_Subjects();
		$rt = $obj->insert($data);
		var_dump($rt);
	}
	public static function editSubject($data,$id)
	{
		$obj = new Application_Model_Db_Subjects();
		$rt = $obj->update($data['name'], 'subject_id ='. $id);
		var_dump($rt);
	}
	public static function deleteSubject($id)
	{
		$obj = new Application_Model_Db_Subjects();
		$obj->delete('subject_id='.(int)$id);
	}
}